<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-refresh-right"
          size="mini"
          @click="handleQuery"
          >刷新</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-star-off"
          size="mini"
          :disabled="single"
          @click="handleDetermine"
          v-hasPermi="['quality:firstPartConfirmation:save']"
        >
          判定
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport('#firstPartConfirmation', '品管首件确认作业')"
        >
          导出
        </el-button>
      </el-col>

      <!-- 分页效果 -->
      <el-col :span="2.2" style="position: absolute; right: 0px; top: 0">
        <Page
          style="margin-right: 0px"
          :current="queryParams.pageNum"
          :page-size="queryParams.pageSize"
          :total="total"
          @on-change="pageChange"
          simple
        ></Page>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      id="firstPartConfirmation"
      highlight-current-row
      border
      stripe
      :height="tableH"
      v-loading="loading"
      :data="firstPartConfirmationList"
      @row-click="handleClick"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" type="index" width="29" align="center" />
      <el-table-column
        label="机台"
        :show-overflow-tooltip="true"
        width="60"
        align="center"
        prop="sjlJtbh"
      />
      <el-table-column
        label="制造单号"
        :show-overflow-tooltip="true"
        width="110"
        align="center"
        prop="moeZzdh"
      />
      <el-table-column
        label="销售单号"
        :show-overflow-tooltip="true"
        width="110"
        align="center"
        prop="moeSodh"
      />
      <el-table-column
        label="物料代码"
        :show-overflow-tooltip="true"
        width="110"
        align="center"
        prop="sjlWldm"
      />
      <el-table-column
        label="品名规格"
        :show-overflow-tooltip="true"
        :width="widthPmgg"
        prop="itmPmgg"
      />
      <el-table-column
        label="模具编号"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="moeMjbh"
      />
      <el-table-column
        label="模具名称"
        :show-overflow-tooltip="true"
        align="center"
        prop="mjmMjmc"
      />
      <el-table-column
        label="穴数"
        :show-overflow-tooltip="true"
        width="50"
        align="center"
        prop="moeXs"
      />
      <el-table-column
        label="单位净重(kg)"
        :show-overflow-tooltip="true"
        width="98"
        align="center"
        prop="itmJz"
      />
      <el-table-column
        label="发出人员"
        :show-overflow-tooltip="true"
        width="73"
        align="center"
        prop="sjlJlrymc"
      />
      <el-table-column
        label="开始时间"
        :show-overflow-tooltip="true"
        align="center"
        prop="sjlKssj"
        width="120"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.sjlKssj, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
    </el-table>

    <!-- 判定品管首件确认作业 -->
    <el-dialog
      title="判定机台"
      v-model="determine"
      class="pdDialog"
      :close-on-click-modal="false"
      width="950px"
    >
      <el-form
        ref="pdForm"
        :model="firstPartDetailList"
        label-width="90px"
        inline
        size="mini"
        class="pdForm"
      >
        <table>
          <tr>
            <hd-form-item-td label="机台编号" size="mini">
              <el-input
                v-model="firstPartDetailList.sjlJtbh"
                readonly
                disabled
                class="readonlyInput"
                style="width: 60px"
              ></el-input>
            </hd-form-item-td>
            <hd-form-item-td label="发出人员" size="mini">
              <el-input
                v-model="firstPartDetailList.sjlJlrymc"
                readonly
                disabled
                class="readonlyInput"
                style="width: 80px"
              ></el-input>
            </hd-form-item-td>
            <hd-form-item-td label="发出时间" size="mini">
              <el-input
                v-model="firstPartDetailList.sjlKssj"
                readonly
                disabled
                class="readonlyInput"
                style="width: 150px"
              ></el-input>
            </hd-form-item-td>
          </tr>
          <tr>
            <hd-form-item-td label="制造单号" size="mini">
              <el-input
                v-model="firstPartDetailList.moeZzdh"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
            </hd-form-item-td>
            <hd-form-item-td colspan="2" label="入库物料" size="mini">
              <el-input
                v-model="firstPartDetailList.moeRkwl"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
              <el-input
                v-model="firstPartDetailList.moeRkpmgg"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
            </hd-form-item-td>
          </tr>
          <tr>
            <hd-form-item-td label="销售单号" size="mini">
              <el-input
                v-model="firstPartDetailList.moeSodh"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
            </hd-form-item-td>
            <hd-form-item-td label="物料代码" size="mini" colspan="2">
              <el-input
                v-model="firstPartDetailList.sjlWldm"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
              <el-input
                v-model="firstPartDetailList.itmPmgg"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
            </hd-form-item-td>
          </tr>
          <tr>
            <hd-form-item-td label="标准穴数" size="mini">
              <el-input
                v-model="firstPartDetailList.mjmXs"
                readonly
                disabled
                class="readonlyInput"
                style="width: 60px"
              ></el-input>
            </hd-form-item-td>

            <hd-form-item-td colspan="2" label="模具编号" size="mini">
              <el-input
                v-model="firstPartDetailList.moeMjbh"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
              <el-input
                v-model="firstPartDetailList.mjmMjmc"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
            </hd-form-item-td>
          </tr>
          <tr>
            <hd-form-item-td label="标准颜色" size="mini">
              <el-input
                disabled
                v-model="firstPartDetailList.itmStandardColor"
              ></el-input>
            </hd-form-item-td>
            <hd-form-item-td colspan="2" label="定额公差" size="mini">
              <el-input
                v-model="firstPartDetailList.gclRate"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
              %
              <el-input
                v-model="firstPartDetailList.gclGram"
                readonly
                disabled
                class="readonlyInput"
                style="width: 180px"
              ></el-input>
              kg
            </hd-form-item-td>
          </tr>
          <tr>
            <td colspan="3">
              <table style="font-size: 14px" class="tabCheck">
                <tr>
                  <th style="width: 52px" rowspan="2"></th>
                  <th style="width: 52px" rowspan="2">标准</th>
                  <th style="width: 52px" rowspan="2">上限值</th>
                  <th style="width: 52px" rowspan="2">下限值</th>
                  <th colspan="8">实测</th>
                </tr>
                <tr>
                  <th>
                    <span style="color: red; width: 2px; height: 2px">*</span>
                    cav1
                  </th>
                  <th>cav2</th>
                  <th>cav3</th>
                  <th>cav4</th>
                  <th>cav5</th>
                  <th>cav6</th>
                  <th>cav7</th>
                  <th>cav8</th>
                </tr>
                <tr>
                  <td>重量(g)</td>
                  <td>{{ firstPartDetailList.itmJz }}</td>
                  <td>
                    {{ firstPartDetailList.top }}
                  </td>
                  <td>
                    {{ firstPartDetailList.bottom }}
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlMz"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlMzOneSavTwo"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlMzOneSavThree"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlMzOneSavFour"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlMzOneSavFive"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlMzOneSavSix"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlMzOneSavSeven"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlMzOneSavEight"
                      class="inputed"
                    />
                  </td>
                </tr>
                <tr>
                  <td>尺寸一</td>
                  <td>
                    {{ parseFloat(firstPartDetailList.itmJccc1).toFixed(2) }}
                  </td>
                  <td>
                    {{ parseFloat(firstPartDetailList.itmJccc1S).toFixed(2) }}
                  </td>
                  <td>
                    {{ parseFloat(firstPartDetailList.itmJccc1X).toFixed(2) }}
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeOneSavOne"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeOneSavTwo"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeOneSavThree"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeOneSavFour"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeOneSavFive"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeOneSavSix"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeOneSavSeven"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeOneSavEight"
                      class="inputed"
                    />
                  </td>
                </tr>
                <tr>
                  <td>尺寸二</td>
                  <!--                  123-->
                  <td>
                    {{ parseFloat(firstPartDetailList.itmJccc2).toFixed(2) }}
                  </td>
                  <td>
                    {{ parseFloat(firstPartDetailList.itmJccc2S).toFixed(2) }}
                  </td>
                  <td>
                    {{ parseFloat(firstPartDetailList.itmJccc2X).toFixed(2) }}
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeTwoSavOne"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeTwoSavTwo"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeTwoSavThree"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeTwoSavFour"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeTwoSavFive"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeTwoSavSix"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeTwoSavSeven"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeTwoSavEight"
                      class="inputed"
                    />
                  </td>
                </tr>
                <tr>
                  <td>尺寸三</td>
                  <td>
                    {{ parseFloat(firstPartDetailList.itmJccc3).toFixed(2) }}
                  </td>
                  <td>
                    {{ parseFloat(firstPartDetailList.itmJccc3S).toFixed(2) }}
                  </td>
                  <td>
                    {{ parseFloat(firstPartDetailList.itmJccc3X).toFixed(2) }}
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeThreeSavOne"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeThreeSavTwo"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeThreeSavThree"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeThreeSavFour"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeThreeSavFive"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeThreeSavSix"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeThreeSavSeven"
                      class="inputed"
                    />
                  </td>
                  <td>
                    <el-input-number
                      size="mini"
                      controls-position="right"
                      v-model="firstPartDetailList.sjlSizeThreeSavEight"
                      class="inputed"
                    />
                  </td>
                </tr>
              </table>
            </td>
          </tr>

          <tr>
            <hd-form-item-td
              colspan="3"
              label="外观"
              size="mini"
              class="appearance"
            >
              <el-checkbox-group v-model="appearance" @change="resetFlag">
                <el-checkbox
                  v-for="item in appearanceList"
                  :label="item.dictLabel"
                ></el-checkbox>
              </el-checkbox-group>
              <el-input
                v-show="appearance.includes('其他')"
                v-model="firstPartDetailList.sjlQtdesc"
              />
            </hd-form-item-td>
          </tr>
          <tr>
            <hd-form-item-td label="颜色" size="mini">
              <el-input v-model="firstPartDetailList.sjlColor"></el-input>
            </hd-form-item-td>
            <hd-form-item-td label="光泽度" size="mini">
              <el-input v-model="firstPartDetailList.sjlGz"></el-input>
            </hd-form-item-td>

            <hd-form-item-td label="判定结果" size="mini">
              <el-select
                v-model="firstPartDetailList.sjlPdjg"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in resultList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </hd-form-item-td>
          </tr>
          <tr>
            <hd-form-item-td label="装配/性能不良" size="mini">
              <el-input v-model="firstPartDetailList.sjlZxDesc"></el-input>
            </hd-form-item-td>
            <hd-form-item-td label="不良现象" size="mini">
              <el-input v-model="firstPartDetailList.sjlYymc"></el-input>
            </hd-form-item-td>
            <hd-form-item-td label="  " size="mini">
              <el-checkbox
                v-model="firstPartDetailList.bjcpygdbf"
                label="报检产品与工单不符"
              ></el-checkbox>
            </hd-form-item-td>
          </tr>
          <tr>
            <hd-form-item-td label="标示不良" size="mini">
              <el-input v-model="firstPartDetailList.sjlBsDesc"></el-input>
            </hd-form-item-td>
            <!-- <hd-form-item-td colspan="3" label="上传附件" size="mini">
              <el-upload action="quality/control/upload_I">
                <el-input v-model="firstPartDetailList.docPath">
                  <el-button slot="append" size="small" type="primary">点击上传</el-button>
                </el-input>
              </el-upload>
            </hd-form-item-td> -->
            <hd-form-item-td colspan="2" label="备注" size="mini">
              <el-input v-model="firstPartDetailList.sjlDesc"></el-input>
            </hd-form-item-td>
          </tr>
        </table>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="handleSave">临时保存</el-button>
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="handlePD">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getDefectiveItem } from "@/api/quality/defectiveItem";
import { exportTable } from "@/utils/ruoyi";
import {
  listFirstPartConfirmation,
  listFirstPartConfirmationDeatil,
  saveFirstPartConfirmation,
} from "@/api/quality/firstPart";

export default {
  name: "FirstPartConfirmation",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      rowData: null,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      determine: false,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      // 总条数
      total: 0,
      tableH: document.body.clientHeight > 900 ? 640 : 450,
      // 品检首件确认作业数据
      firstPartConfirmationList: [],
      firstPartDetailList: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      bodyWidth: document.body.clientWidth,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: document.body.clientHeight > 900 ? 25 : 17,
        bllYydm: null,
        bllYymc: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        bllYydm: [{ required: true, message: "不良代码必填", trigger: "blur" }],
        bllYymc: [{ required: true, message: "不良描述必填", trigger: "blur" }],
      },
      colorList: [
        { value: "本色", label: "本色" },
        { value: "目视", label: "目视" },
      ],
      // 外观列表
      appearanceList: [],
      appearance: [],
      // 判定结果列表
      resultList: [
        { value: "OK", label: "OK" },
        { value: "NG", label: "NG" },
      ],
    };
  },
  created() {
    this.getList();
    this.getDicts("quality_appearance").then((response) => {
      this.appearanceList = response.data;
    });
  },
  computed: {
    widthPmgg() {
      if (this.bodyWidth > 1500) {
        return 300;
      } else {
        return 135;
      }
    },
  },
  methods: {
    /** 查询品管确认作业列表 */
    getList() {
      this.loading = true;
      listFirstPartConfirmation(this.queryParams).then((response) => {
        this.firstPartConfirmationList = response.rows;
        this.total = response.total;
        this.loading = false;
        if (this.total > 0) {
          this.handleClick(this.firstPartConfirmationList[0]);
        }
      });
    },
    // 处理点击事件
    handleClick(row) {
      this.rowData = row;
      this.single = false;
    },
    // 判定页 临时保存
    handleSave() {
      this.firstPartDetailList.flag = "1";
      saveFirstPartConfirmation(this.firstPartDetailList).then((res) => {
        this.msgSuccess("临时保存成功！");
        this.getList();
        this.cancel();
      });
    },
    // 判定页“确定”
    handlePD() {
      // 校验部分
      var that = this.firstPartDetailList;
      this.firstPartDetailList.checkbox = this.appearance;
      if (!that.sjlPdjg || that.sjlPdjg == "" || that.itmMz == null) {
        this.msgError("数据不全");
        return false;
      }

      let msg1 = ["尺寸一", "尺寸二", "尺寸三", "重量"];
      let min = [
        parseFloat(that.itmJccc1X),
        parseFloat(that.itmJccc2X),
        parseFloat(that.itmJccc3X),
        parseFloat(that.bottom),
      ];
      let max = [
        parseFloat(that.itmJccc1S),
        parseFloat(that.itmJccc2S),
        parseFloat(that.itmJccc3S),
        parseFloat(that.top),
      ];
      if (that.sjlPdjg == "OK") {
        if (that.itmJccc1) {
          if (
            that.sjlSizeOneSavOne == null ||
            that.sjlSizeOneSavOne === "" ||
            that.sjlSizeOneSavOne === 0
          ) {
            this.msgError("请输入尺寸");
            return false;
          }
        }
        if (that.itmJccc2) {
          if (
            that.sjlSizeTwoSavOne == null ||
            that.sjlSizeTwoSavOne === "" ||
            that.sjlSizeTwoSavOne === 0
          ) {
            this.msgError("请输入尺寸二");
            return false;
          }
        }
        if (that.itmJccc3) {
          if (
            that.sjlSizeThreeSavOne == null ||
            that.sjlSizeThreeSavOne === "" ||
            that.sjlSizeThreeSavOne === 0
          ) {
            this.msgError("请输入尺寸三");
            return false;
          }
        }
        // 实际净重
        if (that.sjlMz < that.bottom || that.sjlMz > that.top) {
          this.msgError("实际净重不能超出公差范围");
          return;
        }
        //标示不良
        if (that.sjlBsDesc) {
          this.msgError("标示不良，不能判定OK");
          return;
        }
        if (that.sjlZxDesc) {
          this.msgError("装配/性能不良，不能判定OK");
          return;
        }
        //  外观
        if (that.checkbox.length > 0) {
          this.msgError("外观异常，不能判定Ok");
          return;
        }
        // 尺寸判定
        const blnSize = [
          "sjlSizeOne",
          "sjlSizeTwo",
          "sjlSizeThree",
          "sjlMzOne",
        ].some((k1, i1) => {
          return [
            "SavOne",
            "SavTwo",
            "SavThree",
            "SavFour",
            "SavFive",
            "SavSix",
            "SavSeven",
            "SavEight",
          ].some((k2, i2) => {
            if (that[k1 + k2]) {
              if (that[k1 + k2] < min[i1] || that[k1 + k2] > max[i1]) {
                this.msgError(
                  "cav" + (i2 + 1) + msg1[i1] + "超出范围,不能判定OK"
                );
                return true;
              }
            }
          });
        });
        if (blnSize) return false;
        // if (that.itmStandardColor) {
        //   if (that.sjlColor == '本色' || that.sjlColor == '目视') {
        //   } else if (parseFloat(that.itmStandardColor) >= parseFloat(that.sjlColor)) {
        //   } else {
        //     this.msgError('请选择本色，目视，或数字，数字不能超出标准颜色范围，否者不能判定OK')
        //     return
        //   }
        // }
      } else {
        //  如果没填不良现象，则自动判定
        let arrBl = [];
        if (!that.sjlYymc) {
          //标示不良
          if (that.sjlBsDesc) arrBl.push("标示不良");
          if (that.sjlZxDesc) arrBl.push("装配/性能不良");
          //  外观
          if (that.checkbox.length > 0) arrBl.push(that.checkbox.join("、"));
          // 尺寸判定
          let pdArr = ["sjlSizeOne", "sjlSizeTwo", "sjlSizeThree", "sjlMzOne"];
          // 实际净重
          if (that.sjlMz > that.top) {
            arrBl.push("产品超重");
            pdArr.pop();
          } else if (that.sjlMz < that.bottom) {
            arrBl.push("产品过轻");
            pdArr.pop();
          }
          pdArr.forEach((k1, i1) => {
            [
              "SavOne",
              "SavTwo",
              "SavThree",
              "SavFour",
              "SavFive",
              "SavSix",
              "SavSeven",
              "SavEight",
            ].some((k2, i2) => {
              if (that[k1 + k2]) {
                if (that[k1 + k2] < min[i1] || that[k1 + k2] > max[i1]) {
                  arrBl.push(msg1[i1] + "不合格");
                  return true;
                }
              }
            });
          });
          // if (that.itmStandardColor) {
          //   if (that.sjlColor == '本色' || that.sjlColor == '目视') {
          //   } else if (parseFloat(that.itmStandardColor) >= parseFloat(that.sjlColor)) {
          //   } else {
          //     arrBl.push('颜色不合格')
          //   }
          // }
          that.sjlYymc = arrBl.join(";");
        }
        that.sjlYymc = that.sjlYymc || "";
        if (that.bjcpygdbf && that.sjlYymc.indexOf(";报检产品与工单不符") < 0) {
          that.sjlYymc += ";报检产品与工单不符";
        } else {
          that.sjlYymc = that.sjlYymc.replace(/;?报检产品与工单不符/, "");
        }
        that.sjlYymc = that.sjlYymc.replace(/^;/, "");
        if (that.sjlYymc === "") {
          this.msgError("尺寸重量颜色参数正常，判定NG时请填写不良现象");
          return;
        }
      }
      this.firstPartDetailList.flag = "2";
      this.resetFlag();
      saveFirstPartConfirmation(this.handleWeight()).then((res) => {
        this.msgSuccess("保存成功！");
        this.getList();
        this.cancel();
      });
    },
    handleWeight() {
      // 复制一份数据处理
      let tmp = Object.assign({}, this.firstPartDetailList);
      tmp.itmJz = (tmp.itmJz / 1000).toFixed(5);
      tmp.sjlMz = (tmp.sjlMz / 1000).toFixed(5);
      tmp.sjlMzOneSavTwo = (tmp.sjlMzOneSavTwo / 1000).toFixed(5);
      tmp.sjlMzOneSavThree = (tmp.sjlMzOneSavThree / 1000).toFixed(5);
      tmp.sjlMzOneSavFour = (tmp.sjlMzOneSavFour / 1000).toFixed(5);
      tmp.sjlMzOneSavFive = (tmp.sjlMzOneSavFive / 1000).toFixed(5);
      tmp.sjlMzOneSavSix = (tmp.sjlMzOneSavSix / 1000).toFixed(5);
      tmp.sjlMzOneSavSeven = (tmp.sjlMzOneSavSeven / 1000).toFixed(5);
      tmp.sjlMzOneSavEight = (tmp.sjlMzOneSavEight / 1000).toFixed(5);
      return tmp;
    },
    // 修改页取消按钮
    cancel() {
      this.open = false;
      this.determine = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        sjlJtbh: null,
        moeZzdh: null,
        moeSodh: null,
        itmCustwldm: null,
        sjlWldm: null,
        itmPmgg: null,
        moeMjbh: null,
        mjmMjmc: null,
        moeXs: null,
        itmSkzl: null,
        itmJz: null,
        itmMz: null,
        sjlJlrymc: null,
        sjlKssj: null,
        sjlId: null,
        sjlGlid: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加品检不良项目";
    },
    /** 修改按钮操作 */
    handleCheck(row) {
      this.reset();
      const bllYydm = row.bllYydm || this.ids;
      getDefectiveItem(bllYydm).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改品检不良项目";
      });
    },
    /** 导出按钮操作 */
    handleExport(a, b) {
      exportTable(a, b);
    },
    /** 判定按钮操作 */
    handleDetermine() {
      listFirstPartConfirmationDeatil(this.rowData.sjlId).then((res) => {
        this.firstPartDetailList = res.data[0];

        // if (!this.firstPartDetailList.sjlColor) {
        //   this.firstPartDetailList.sjlColor = '目视'
        // }
        if (
          this.firstPartDetailList.gclRate &&
          parseFloat(this.firstPartDetailList.gclRate) > 0
        ) {
          this.firstPartDetailList.top = parseFloat(
            this.firstPartDetailList.itmJz *
              (1 + this.firstPartDetailList.gclRate / 100) *
              1000
          ).toFixed(2);
          this.firstPartDetailList.bottom = parseFloat(
            this.firstPartDetailList.itmJz *
              (1 - this.firstPartDetailList.gclRate / 100) *
              1000
          ).toFixed(2);
        } else if (this.firstPartDetailList.gclGram) {
          this.firstPartDetailList.top = parseFloat(
            (parseFloat(this.firstPartDetailList.itmJz) +
              parseFloat(this.firstPartDetailList.gclGram)) *
              1000
          ).toFixed(2);
          this.firstPartDetailList.bottom = parseFloat(
            (parseFloat(this.firstPartDetailList.itmJz) -
              parseFloat(this.firstPartDetailList.gclGram)) *
              1000
          ).toFixed(2);
        }

        this.titleBh =
          "判定机台" + "[" + this.firstPartDetailList.sjlJtbh + "]";
        let c = [];
        this.firstPartDetailList.itmJz = (
          this.firstPartDetailList.itmJz * 1000
        ).toFixed(2);
        //TODO 处理回显Flag
        if (this.firstPartDetailList.sjlMdflag) {
          c.push(this.firstPartDetailList.sjlMdflag);
        }
        if (this.firstPartDetailList.sjlQpflag) {
          c.push(this.firstPartDetailList.sjlQpflag);
        }
        if (this.firstPartDetailList.sjlSsflag) {
          c.push(this.firstPartDetailList.sjlSsflag);
        }
        if (this.firstPartDetailList.sjlBxflag) {
          c.push(this.firstPartDetailList.sjlBxflag);
        }
        if (this.firstPartDetailList.sjlQwflag) {
          c.push(this.firstPartDetailList.sjlQwflag);
        }
        if (this.firstPartDetailList.sjlFmflag) {
          c.push(this.firstPartDetailList.sjlFmflag);
        }
        if (this.firstPartDetailList.sjlHsflag) {
          c.push(this.firstPartDetailList.sjlHsflag);
        }
        if (this.firstPartDetailList.sjlRjflag) {
          c.push(this.firstPartDetailList.sjlRjflag);
        }
        if (this.firstPartDetailList.sjlQjflag) {
          c.push(this.firstPartDetailList.sjlQjflag);
        }
        if (this.firstPartDetailList.sjlFcflag) {
          c.push(this.firstPartDetailList.sjlFcflag);
        }
        if (this.firstPartDetailList.sjlDbflag) {
          c.push(this.firstPartDetailList.sjlDbflag);
        }
        if (this.firstPartDetailList.sjlScflag) {
          c.push(this.firstPartDetailList.sjlScflag);
        }
        if (this.firstPartDetailList.sjlFsflag) {
          c.push(this.firstPartDetailList.sjlFsflag);
        }
        if (this.firstPartDetailList.sjlZsflag) {
          c.push(this.firstPartDetailList.sjlZsflag);
        }
        if (this.firstPartDetailList.sjlLlflag) {
          c.push(this.firstPartDetailList.sjlLlflag);
        }
        if (this.firstPartDetailList.sjlBmghflag) {
          c.push(this.firstPartDetailList.sjlBmghflag);
        }
        if (this.firstPartDetailList.sjlQtflag) {
          c.push(this.firstPartDetailList.sjlQtflag);
        }
        this.appearance = c;
        this.determine = true;
      });
    },
    /** 分页 **/
    pageChange(page) {
      this.queryParams.pageNum = page;
      this.getList();
    },
    resetFlag() {
      if (this.appearance.includes("黑点")) {
        this.firstPartDetailList.sjlMdflag = "黑点";
      } else {
        this.firstPartDetailList.sjlMdflag = null;
      }

      if (this.appearance.includes("气泡")) {
        this.firstPartDetailList.sjlQpflag = "气泡";
      } else {
        this.firstPartDetailList.sjlQpflag = null;
      }

      if (this.appearance.includes("缩水")) {
        this.firstPartDetailList.sjlSsflag = "缩水";
      } else {
        this.firstPartDetailList.sjlSsflag = null;
      }

      if (this.appearance.includes("变形")) {
        this.firstPartDetailList.sjlBxflag = "变形";
      } else {
        this.firstPartDetailList.sjlBxflag = null;
      }

      if (this.appearance.includes("气纹")) {
        this.firstPartDetailList.sjlQwflag = "气纹";
      } else {
        this.firstPartDetailList.sjlQwflag = null;
      }

      if (this.appearance.includes("飞边、毛刺")) {
        this.firstPartDetailList.sjlFmflag = "飞边、毛刺";
      } else {
        this.firstPartDetailList.sjlFmflag = null;
      }

      if (this.appearance.includes("划伤")) {
        this.firstPartDetailList.sjlHsflag = "划伤";
      } else {
        this.firstPartDetailList.sjlHsflag = null;
      }

      if (this.appearance.includes("熔接线")) {
        this.firstPartDetailList.sjlRjflag = "熔接线";
      } else {
        this.firstPartDetailList.sjlRjflag = null;
      }

      if (this.appearance.includes("缺胶")) {
        this.firstPartDetailList.sjlQjflag = "缺胶";
      } else {
        this.firstPartDetailList.sjlQjflag = null;
      }

      if (this.appearance.includes("分层")) {
        this.firstPartDetailList.sjlFcflag = "分层";
      } else {
        this.firstPartDetailList.sjlFcflag = null;
      }

      if (this.appearance.includes("顶白")) {
        this.firstPartDetailList.sjlDbflag = "顶白";
      } else {
        this.firstPartDetailList.sjlDbflag = null;
      }

      if (this.appearance.includes("色差")) {
        this.firstPartDetailList.sjlScflag = "色差";
      } else {
        this.firstPartDetailList.sjlScflag = null;
      }

      if (this.appearance.includes("分色")) {
        this.firstPartDetailList.sjlFsflag = "分色";
      } else {
        this.firstPartDetailList.sjlFsflag = null;
      }

      if (this.appearance.includes("杂色")) {
        this.firstPartDetailList.sjlZsflag = "杂色";
      } else {
        this.firstPartDetailList.sjlZsflag = null;
      }

      if (this.appearance.includes("冷料斑")) {
        this.firstPartDetailList.sjlLlflag = "冷料斑";
      } else {
        this.firstPartDetailList.sjlLlflag = null;
      }
      if (this.appearance.includes("表面光滑")) {
        this.firstPartDetailList.sjlBmghflag = "表面光滑";
      } else {
        this.firstPartDetailList.sjlBmghflag = null;
      }

      if (this.appearance.includes("其他")) {
        this.firstPartDetailList.sjlQtflag = "其他";
      } else {
        this.firstPartDetailList.sjlQtflag = null;
      }
    },
  },
};
</script>

<style scoped lang="less">
.app-container {
  .mb8 {
  }
  #firstPartConfirmation {
  }
  .pdDialog {
    .pdForm {
      .tabCheck {
        table-layout: fixed;
        border-collapse: collapse;
        border: 1px solid black;
        width: 100%;
        td,
        th {
          border: 1px solid black;
          ::v-deep .el-input-number--mini {
            width: auto;
          }
        }
        /deep/.ipt.el-input.el-input--mini {
          height: 18px;
          .el-input__inner {
            display: inline-block;
            height: 18px !important;
            border: none;
            padding: 0px !important;
            text-align: center;
          }
        }
      }
      /deep/ .appearance .el-form-item__content {
        width: calc(100% - 100px);
      }
      /deep/ .el-input-number .el-input__inner {
        padding: 0px 28px 0px 2px;
      }
    }
  }
}
</style>
